import 'package:animal/constant/index_constant.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

import 'code_input_controller.dart';

///短信验证码输入框
class CodeInputPage extends StatelessWidget {
  final TextEditingController textEditingController;
  final TextEditingController phoneEditingController;
  final TextStyle? style;
  final TextStyle? textStyle;
  final int? maxLength;
  final Decoration? decoration;
  final Color? btnColor;
  final String? tag;

  const CodeInputPage({
    Key? key,
    required this.textEditingController,
    required this.phoneEditingController,
    this.style,
    this.textStyle,
    this.maxLength,
    this.decoration,
    this.btnColor,
    this.tag,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(CodeInputController(codeEditingController: textEditingController, phoneEditingController: phoneEditingController),tag: tag);
    return Container(
      decoration: decoration ?? BoxDecoration(border: Border(bottom: BorderSide(width: ScreenUtil().L(0.5), color: KColorConstant.lineE2E5E8))),
      child: Row(
        children: [
          Expanded(
            child: TextFormField(
              maxLines: 1,
              maxLength: maxLength ?? 4,
              onSaved: (value) {},
              controller: textEditingController,
              textAlign: TextAlign.left,
              style: style ?? KFontConstant.myTextStyle(size: 15),
              inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'[0-9]'))],
              decoration: InputDecoration(
                counterText: "",
                hintText: ('请输入验证码'),
                contentPadding: const EdgeInsets.only(top: -5, bottom: 0),
                hintStyle: textStyle??KFontConstant.myTextStyle(size: 15, color: KColorConstant.black999999),
                alignLabelWithHint: true,
                border: const OutlineInputBorder(borderSide: BorderSide.none),
              ),
            ),
          ),
          Obx(() {
            return SizedBox(
              width: ScreenUtil().L(75),
              child: GFButton(
                onPressed: () => controller.sendSms(),
                fullWidthButton: true,
                text: controller.btnName.value,
                disabledColor: Colors.grey.withOpacity(0.1),
                //按钮禁用时的颜色
                disabledTextColor: Colors.white,
                size: ScreenUtil().L(20),
                textStyle: KFontConstant.myTextStyle(size: 12, color: controller.btnColor.value),
                color: btnColor??KColorConstant.blue3C5A99,
                shape: GFButtonShape.pills,
                splashColor: Colors.transparent,
                type: controller.isButtonEnable.value ? GFButtonType.solid : GFButtonType.transparent,
              ),
            );
          }),
        ],
      ),
    );
  }
}
